//
//  GodsEvaluateListCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/9.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "GodsEvaluateListCell.h"
#import "ImageBrowser.h"
@interface GodsEvaluateListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *firstBtn;
@property (weak, nonatomic) IBOutlet UIButton *twoBtn;
@property (weak, nonatomic) IBOutlet UIButton *threeBtn;
@property (weak, nonatomic) IBOutlet UIButton *fourBtn;

@property (weak, nonatomic) IBOutlet UIButton *fiveBtn;

@property (weak, nonatomic) IBOutlet ImageBrowser *myCollectionVeiw;
@property (weak, nonatomic) IBOutlet UILabel *bottomTopLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBgH;

@property (nonatomic, strong) NSMutableArray<NSURL *> *urls;

@property (weak, nonatomic) IBOutlet UILabel *bottomBottomLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLabelFirstMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLabelTwoMargin;

@end

@implementation GodsEvaluateListCell

- (NSMutableArray<NSURL *> *)urls{
    if (!_urls) {
        _urls = [NSMutableArray array];
    }
    
    
    return _urls;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    

    self.nickNameLabel.font = MYFONT(14);
    
    self.contentLabel.font = MYFONT(16);
    
    self.iconImageView.layer.masksToBounds = YES;
    
    self.iconImageView.layer.cornerRadius = 22;
    
    self.rightTimeLabel.font = MYFONT(14);
    
    self.rightTimeLabel.textColor = darkGray;
    
    self.bottomTopLabel.font = MYFONT(12);
    self.bottomBottomLabel.font = MYFONT(12);
    self.bottomBottomLabel.textColor = darkGray;
    self.bottomTopLabel.textColor = darkGray;
    
    self.bottomMargin.constant = 0;
    
//    self.myCollectionVeiw.backgroundColor = [UIColor blueColor];
    
    
  
    // Initialization code
}


- (void)setModel:(GodsEvaluListModel *)model{
    
    _model = model;
    
    
    [self.urls removeAllObjects];

    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:_model.user_headimg] placeholderImage:[UIImage defaulIconImage]];
    
    self.contentLabel.attributedText = [self attributedString:_model.content withFont:MYFONT(16)];
    
    self.rightTimeLabel.text = _model.addtime;
    
    self.nickNameLabel.text = _model.nick_name;
    
    
    if (_model.suk_name.length > 0) {
        
        self.bottomTopLabel.text = _model.suk_name;
        
        self.bottomBgH.constant = 72;
        
        self.bottomLabelFirstMargin.constant = 6;
        self.bottomLabelTwoMargin.constant = 8;

    } else {
        self.bottomTopLabel.text = _model.suk_name;
        self.bottomBgH.constant = 36;
        self.bottomLabelFirstMargin.constant = 0;
        self.bottomLabelTwoMargin.constant = 0;
    }

    self.bottomBottomLabel.text = [NSString stringWithFormat:@"购买日期: %@",_model.buy_time];
    
    
    for (NSString *urlstr in _model.image) {
        
       
        [self.urls addObject:[NSURL URLWithString:urlstr]];
    }
    
    
//    NSLog(@"%ld888888888",self.urls.count);
    
    self.myCollectionVeiw.thumPicURLs = self.urls;
    
    BrowserLayout *layout = (BrowserLayout *)self.myCollectionVeiw.collectionViewLayout;
    
    layout.itemSize = [layout itemSizeWitUrls:self.urls withMargin:89];
    
    CGSize tempSize = [layout myCollectionViewSizeWitUrls:self.urls withMargin:89];
    
    self.collectionW.constant = tempSize.width;
    
    self.collectionH.constant = tempSize.height;
    
    [self.myCollectionVeiw reloadData];
    
}




- (NSAttributedString *)attributedString:(NSString *)str withFont:(UIFont *)font{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSKernAttributeName value:@(1.0f) range:NSMakeRange(0, str.length)];
    
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
    
    para.lineSpacing = 1;
    
//    para.firstLineHeadIndent = 20;
    
    [attr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, str.length)];
    
    
    return attr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
